package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.BuyerBean;
import com.project.bean.UserBean;
import com.project.service.IBuyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("buyer")
public class BuyerController {
    @Autowired
    private IBuyerService buyerService;

    @RequestMapping("add")
    public String add(HttpServletRequest req, BuyerBean buyer) {
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        buyerService.add(buyer, user.getId());
        return "ok";
    }

    @RequestMapping("findById")
    public BuyerBean findById(Integer id) {
        System.out.println(buyerService.findById(id));
        return buyerService.findById(id);
    }

    @RequestMapping("findByItem")
    public IPage<BuyerBean> findByItem(Integer pageNo, String name, LocalDate startDate, LocalDate endDate) {

        return buyerService.findByItem(pageNo, name, startDate, endDate);
    }
}
